using Core.SimpleTemp.Common;
using Core.SimpleTemp.Common.PagingQuery;
using Core.SimpleTemp.Entitys;
using Core.SimpleTemp.Repositories;
using Core.Toolkit.Common;
using Core.Toolkit.Core;
using Core.Toolkit.Core.Api;
using Core.Toolkit.Core.Application;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Core.SimpleTemp.Application
{
    [AutoDi()]
    public class YH_StandingBookAttachmentService : BaseAppService<YH_StandingBookAttachmentDto, YH_StandingBookAttachment , YH_StandingBookAttachmentRepository>
        {
        readonly ExcelHelp _excelHelp;
        public YH_StandingBookAttachmentService (YH_StandingBookAttachmentRepository repository,ExcelHelp excelHelp) : base(repository){
        _excelHelp = excelHelp;
        }



        private LoadPageOffsetModelAuto<YH_StandingBookAttachment, YH_StandingBookAttachmentDto>
            GetLoadPageOffsetMode(PagingModel<YH_StandingBookAttachmentDto>
                pagingQueryModel)
                {
                var loadPageOffsetModel = this.GetLoadPageOffsetModelAuto(pagingQueryModel);
                var baseQuery = _repository.QueryBase().AsNoTracking();
                loadPageOffsetModel.QueryWhere = this.CreateQRList()

         .Add("StandingBookId","=") 
         .Add("Type","=") 
         .Add("Attachment","=") 
         .Add("CreateDept","=") 
         .Add("UpdateDept","=") ;


                loadPageOffsetModel.BasqQuery = baseQuery;
                loadPageOffsetModel.Order = orderModel => orderModel.CreateTime;
                loadPageOffsetModel.Selector = model => new  YH_StandingBookAttachment() {
                Id = model.Id,
StandingBookId= model.StandingBookId,
Type= model.Type,
Attachment= model.Attachment,
CreateDept= model.CreateDept,
UpdateDept= model.UpdateDept,
                };
                return loadPageOffsetModel;
                }


                public async Task <IPageModel<YH_StandingBookAttachmentDto>> GetList(PagingModel<YH_StandingBookAttachmentDto>
                    pagingQueryModel)
                    {
                    var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
                    return await base.LoadPageOffsetAsync(loadPageOffsetModel);
                    }


                    public async Task<string>
                        Export(PagingModel<YH_StandingBookAttachmentDto>
                            pagingQueryModel)
                            {
                            var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
                            var DataList = await this.ExportDataAsync(loadPageOffsetModel);
                            var excelData = DataList.Select(model => new
                            {
model.StandingBookId,
StandingBookId_title ="隐患台账ID",
model.Type,
Type_title ="类型 (整改前0/整改后 1)",
model.Attachment,
Attachment_title ="附件",
model.CreateDept,
CreateDept_title ="",
model.UpdateDept,
UpdateDept_title ="",
                            }).ToList();




                            return _excelHelp.Create(excelData);
                            }

                            }

                            }
